package com.tywj.panda.driver.api

import androidx.collection.ArrayMap
import com.tywj.lib.core.common.util.TimeUtil
import com.tywj.lib.net.retrofit.request.GetRequest
import com.tywj.lib.net.retrofit.request.PostRequest
import com.tywj.panda.customer.common.api.CommonApi
import com.tywj.panda.customer.common.manager.AuthorityManager
import com.tywj.panda.customer.common.tool.HttpTool
import com.tywj.panda.driver.entity.DriverTaskEntity


/**
 * @desc 首页网络请求接口
 * @author June Yang
 * @date 2020/5/18
 */
object DriverApi {

    //司机端使用 司机端使用 司机端使用 查询司机端线路班次列表（首页列表）
    var GET_TASK_STORE = CommonApi.API_TICKET_URL + "ticket/inspect/driver/store"

    var GET_TICKETS_DETAILS = CommonApi.API_TICKET_URL + "ticket/inspect/driver/search"

    //余额
    var GET_BLANCE = CommonApi.API_TICKET_URL + "ticket/driver/starLight"

    //上传轨迹坐标
    private var SAVE_DRIVER_POS = CommonApi.API_ROUTE_URL + "gps/route"

    //余额流水
    private var GET_BLANCE_WATER = CommonApi.API_TICKET_URL + "ticket/driver/achievement"


    //GET /ticket/inspect/driver/store

    fun getTaskList(): GetRequest {
        return HttpTool.get(GET_TASK_STORE)
    }

    /**
     *
     */
    fun listTaskParams(taskStatus: String, selectedTime: String = "", time: String = ""): ArrayMap<String, String> {
        val map = ArrayMap<String, String>()
        map["driver_code"] = AuthorityManager.uid
        map["status"] = taskStatus
        map["page_size"] = "10" //分页大小
        map["page_type"] = "1" //1:当前时间之前(下一页、加载更多) 2:当前时间之后（上一页)

        //线路日期
        if (selectedTime.isEmpty()) {
            map["line_date"] = TimeUtil.millis2String(System.currentTimeMillis(), TimeUtil.PATTERN_FORMAT)
        } else {
            map["line_date"] = selectedTime
        }

        //分页用
        if (time.isEmpty()) {
//            map["create_time"] = TimeUtil.millis2String(System.currentTimeMillis(), TimeUtil.PATTERN_FORMAT)
            map["create_time"] = ""
        } else {
            map["create_time"] = time
        }
        return map
    }

    fun getTicketDetails(bean: DriverTaskEntity.DataBean): GetRequest {
        return HttpTool.get(GET_TICKETS_DETAILS)
            .param("line_code", bean.lineCode)
            .param("line_date", bean.lineDate)
            .param("line_time", bean.lineTime)
            .param("driver_code", AuthorityManager.uid)
    }

    /**
     * 获取余额
     * http://192.168.2.192:9002/fnc/driver/starLight?driver_code=467676735333203968
     */
    fun getBalance(): GetRequest {
        return HttpTool.get(GET_BLANCE).param("driver_code", AuthorityManager.uid)
    }

    /**
     * 绩效流水
     * http://192.168.2.192:9002/fnc/driver/achievement?driver_code=467676735333203968&page_type=1
     */
    //分页问题
    fun getBalanceWater(): GetRequest {
        return HttpTool.get(GET_BLANCE_WATER)
    }

    fun listWaterParams(
        lineDate: String = ""
    ): ArrayMap<String, String> {
        val map = ArrayMap<String, String>()
        map["create_time"] = lineDate
        map["driver_code"] = AuthorityManager.uid
        map["page_type"] = "1"
        return map
    }

    /**
     * @param lineCode 线路ID
     * @param locList 经度值,纬度值
     * @param storeNo 班次ID
     * @param vehicleNo 车辆编号
     * @param VehicleCode 车牌号
     */
    fun saveAddress(
        locList: ArrayList<Double>,
        addressName: String = "",
        bean: DriverTaskEntity.DataBean,
        workStatus: Int = 0
    ): PostRequest {
        return HttpTool.post(SAVE_DRIVER_POS)
            .param("loc", locList)
            .param("name", addressName)
            .param("uid", AuthorityManager.uid)

            .param("store_no", bean.storeNo)
            .param("vehicle_no", bean.vehicleNo)
            .param("vehicle_code", bean.vehicleCode)
            .param("line_code", bean.lineCode)
            .param("work_status", workStatus)
    }
}